import { getCategoryAPI, getCategoryFilterAPI, getSubCategoryAPI } from '@/apis/category'
import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCategoryAPI = defineStore('reclassify', () => {
    const categoryList = ref({})
    const categoryAPI = async (data) => {
        let res = await getCategoryAPI(data)
        if (res.code == 1) {
            categoryList.value = res.result
        }
    }

    return { categoryList, categoryAPI }
})


export const useCategoryFilterAPI = defineStore('reclassify2', () => {
    const categoryFilterList = ref({})
    const categoryFilterAPI = async (data) => {
        let res = await getCategoryFilterAPI(data)
        if (res.code == 1) {
            categoryFilterList.value = res.result
        }
    }

    return { categoryFilterList, categoryFilterAPI }
})

export const useSubCategoryAPI = defineStore('reclassify3', () => {
    const subCategoryList = ref([])
    const subCategoryAPI = async (data) => {
        let res = await getSubCategoryAPI(data)
        if (res.code == 1) {
            subCategoryList.value = res.result.items
            // console.log(subCategoryList.value);
        }
    }

    return { subCategoryAPI, subCategoryList }
})